home *** CD-ROM | disk | FTP | other *** search
- ##############################################################################
- # rcptto.mml
- #
- # MailShield script that is run after each SMTP RCPT TO: command
- #
-
- ##############################################################################
- # log this MAIL FROM message
- #
- # &LogMessage("SMTP RCPT TO: '".$SmtpRcptTo."'");
-
-
- ##############################################################################
- # Sleep for a few seconds if more than a certain number of recipients,
- # for each recipient over that limit. This prevents people who are allowed
- # to relay through you from abusing that right and sending thousands
- # of recipients through.
-
- if (scalar(@SmtpRcptTo) >= $slow_threshold) {
- &LogMessage("Waiting 2 seconds for recipient number: ".scalar(@SmtpRcptTo), "log_refuse");
- sleep(2);
- };
-
-
- ##############################################################################
- # Sleep for a number of seconds if we have been instructed to tarpit this connection.
-
- if ($tarpit) {
- sleep($tarpit_delay);
- };
-
-
- ##############################################################################
- # Check to see if this is a valid user on the destination server
-
- if ($chk_rcpt) {
- if (!&CheckRcptSmtpTcpip($SmtpRcptTo, $smtp_server)) {
- &Message("550 <".$SmtpRcptTo.">... no such user (reported by Mail Server)");
- $SmtpRcptTo = "";
- return;
- };
- };
-
-
- ##############################################################################
- # Check to see if they are using a colon or percent sign to redirect the recipient
-
- if ((index($SmtpRcptTo, ":") > -1) || (index($SmtpRcptTo, "%") > -1) || (index($SmtpRcptTo, "!") > -1)) {
- &Message("550 : or % or ! redirected recipients are not allowed");
- $SmtpRcptTo = "";
- return;
- };
-
-
- ##############################################################################
- # Check to see if more than one @ in the RCPT TO field
-
- @at_array = &extract(/\@/, $SmtpRcptTo);
- if (scalar(@at_array) > 1) {
- &Message("550 : Too many @ characters in destination address");
- $SmtpRcptTo = "";
- return;
- };
-
-
- ##############################################################################
- # If this host has been accepted for relaying in begin.mml, the perform no more tests
-
- if ($accept) {
- exit;
- };
-
- ##############################################################################
- # check for email addresses that we always accept mail to
-
- if (scalar(@ok_rcptto) > 0) {
- if (index(lc($SmtpRcptTo), @ok_rcptto) > -1) {
- $accept = TRUE;
- &MessageAppend(" (RCPT TO address approved for relaying)");
- exit;
- };
- };
-
-
- ##############################################################################
- # Determine if the recipient is local or not, and refuse relaying if it is not
- #
- # Note: in begin.mml the connecting host is checked to see if they are
- # allowed to relay mail, and if they are (at that point), the &Accept command
- # is given to stop further checking. If, at this point, a non-local email
- # address is specified as the recipient, then this is a relay request, and
- # is refused.
- #
- # Note #2: if no local domains are specified in config.mml, then this test
- # is skipped.
-
- if ($reject_relaying) {
- if ((index(lc($SmtpRcptTo), @local_domains) == -1) && (scalar(@local_domains) > 0)) {
- $smtp_message = "550 Relaying is not allowed";
- $log_message = "550 Relay request denied, and ".$SmtpRcptTo." is not a local domain name.";
- $relay_rejection = TRUE;
- &DefaultRejection;
- };
- };
-
- ##############################################################################
- # check for email addresses that we do not accept mail to
-
- if (scalar(@no_rcptto) > 0) {
- if (index(lc($SmtpRcptTo), @no_rcptto) > -1) {
- $smtp_message = "550 Recipient refused.";
- $log_message = "550 Recipient is on banned RCPT TO list / matched ".$match;
- &DefaultRejection;
- };
- };
-
-
- ##############################################################################
- # Check for maximum number of RCPT TO: allowed
-
- if (scalar(@SmtpRcptTo) >= $max_rcpt_to) {
- $smtp_message = "550 Too many recipients";
- $log_message = "550 Maximum number of recipients was exceeded. Maximum is ".$max_rcpt_to;
- &DefaultRejection;
- };
-
-
- ##############################################################################
- # Do a gentle tarpitting if too many RCPT TO: are specified
-
- if ($tarpit_rcpt_to_threshold > 0) {
- if (scalar(@SmtpRcptTo) >= $tarpit_rcpt_to_threshold) {
- # the first time we start tarpitting RCPT TO, log it
- if ($first_time_tarpit_rcpt != 1) {
- $first_time_tarpit_rcpt = 1;
- &LogMessage("Tarpitting RCPT TO from host: ".$PeerHostname." [".$PeerTcpip."]", "log_refuse");
- };
- sleep(5);
- };
- };
-
-
- ##############################################################################
- # Check for blank MAIL FROM and more than one recipient
-
- if ($onercpt) {
- if (length($SmtpMailFrom) == 0) {
- if (scalar(@SmtpRcptTo) > 1) {
- $smtp_message = "550 Message rejected";
- $log_message = "550 Message rejected because MAIL FROM was blank and more than 1 recipient was specified";
- &DefaultRejection;
- };
- };
- };
-
-
-